package com.ruoyi.customerService.controller;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.InitTableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.customerService.domain.CsSignRateUnStandardExamine;
import com.ruoyi.customerService.domain.vo.CsSignRateUnStandardExamineVo;
import com.ruoyi.customerService.service.CsSignRateUnStandardExamineService;
import com.ruoyi.logistic.domain.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cs/signRateUnStandardExamine")
@Api(tags = "客服中心-签收率未达标考核")
public class CsSignRateUnStandardExamineController {
    @Autowired
    private CsSignRateUnStandardExamineService csSignRateUnStandardExamineService;
    @Autowired
    private TableService tableService;

    @ApiOperation("汇总")
    @PostMapping("/collect")
    public R collect(@RequestBody CsSignRateUnStandardExamineVo vo){
        if (vo.getStartTime() == null || vo.getEndTime() == null || vo.getTimeType() == null){
            return R.fail("暂无数据");
        }
        List<CsSignRateUnStandardExamine> examines = csSignRateUnStandardExamineService.collect(vo);
        if (examines == null || examines.size() == 0){
            return R.fail("暂无数据");
        }else {
            JSONObject jsonObject = new JSONObject();
            String[] fields = {"collectDate","networkName", "belong", "signedTotal"
                    , "d1SignRateGoal", "d1Goal", "d1Total", "d1NoSignTotal", "d1SignRate", "d1NoStandardTotal", "d1Penalty", "d1Amount"
                    , "d2SignRateGoal", "d2Goal", "d2Total", "d2NoSignTotal", "d2SignRate", "d2NoStandardTotal", "d2Penalty", "d2Amount"
                    , "d3SignRateGoal", "d3Goal", "d3Total", "d3NoSignTotal", "d3SignRate", "d3NoStandardTotal", "d3Penalty", "d3Amount"};
            InitTableVo initTableVo = new InitTableVo();
            initTableVo.setFields(fields);
            initTableVo.setCode("csSignRateUnStandard");
            jsonObject.put("list",PageInfo.info(examines));
            jsonObject.put("fields", tableService.initTable(initTableVo));
            return R.ok(jsonObject);
        }

    }
}
